from dataclasses import dataclass, field
from typing import Optional
from datetime import datetime

@dataclass
class BookIndexDTO:
    """
    数据传输对象 - 小说目录表
    """
    id: int = field(metadata={"description": "主键"})
    book_id: int = field(metadata={"description": "小说ID"})
    index_num: int = field(metadata={"description": "目录号"})
    index_name: Optional[str] = field(default=None, metadata={"description": "目录名"})
    word_count: Optional[int] = field(default=None, metadata={"description": "字数"})
    is_vip: bool = field(default=False, metadata={"description": "是否收费，1：收费，0：免费"})
    book_price: int = field(default=0, metadata={"description": "章节费用（屋币）"})
    storage_type: str = field(default="db", metadata={"description": "存储方式"})
    content: Optional[str] = field(default=None, metadata={"description": "章节内容"})


    def __post_init__(self):
        # 确保 is_vip 是布尔类型
        if isinstance(self.is_vip, int):
            self.is_vip = bool(self.is_vip)
